(() => {

    // 定义泛型接口
    interface IBaseCRUD<T> {
        data: Array<T>
        add: (t: T) => T
        getUserId: (id: number) => T
    }

    // 用户类
    class User {
        id?: number
        name: string
        age: number
        // 构造函数
        constructor(name: string, age: number) {
            this.name = name
            this.age = age
        }
    }

    // 定义一个类，进行增删改查
    class UserCRUD implements IBaseCRUD<User> {
        data: Array<User> = []
        //添加用户
        add(user: User): User {
            user.id = Date.now() + Math.random()
            this.data.push(user)
            return user
        }

        // 根据id进行查询用户信息
        getUserId(id: number): User {
            return this.data.find(user => user.id === id)
        }
    }

    // 实例化添加用户信息的类userCRUD
    const userCRUD: UserCRUD = new UserCRUD()
    // 调用添加数据的方法
    userCRUD.add(new User('jack', 18))
    userCRUD.add(new User('tom', 19))
    userCRUD.add(new User('lucy', 11))
    userCRUD.add(new User('ui', 17))
    userCRUD.add(new User('java', 18))
    console.log(UserCRUD.data);

})()